//
//  ControlView.m
//  Civacrm
//
//  Created by 王桂敏 on 2017/3/24.
//  Copyright © 2017年 王桂敏. All rights reserved.
//

#import "ControlView.h"

@interface ControlView ()

@property (nonatomic,assign) CGRect downFrame;

@property (nonatomic,assign) CGRect upFrame;

@end
@implementation ControlView

- (id)initWithDownFrame:(CGRect)downFrame upFrame:(CGRect)upFrame{
    self = [super init];
    if (self) {
        self.downFrame = downFrame;
        self.upFrame = upFrame;
        [self initData];
        [self initView];
    }
    return self;
}

- (void)initData{
    self.isShow = YES;
}

- (void)initView{
    self.downView.userInteractionEnabled = YES;
    
    self.upView.userInteractionEnabled = YES;
}

- (UIView *)downView{
    if (!_downView) {
        self.downView = [UIView viewWithFrame:self.downFrame bgColor:ClearColor];
        
        UIView *view = [UIView viewWithFrame:_downView.bounds bgColor:BlackColor];
        view.alpha = 0.5;
        [_downView addSubview:view];
        
        self.prograssSlider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, self.downView.width, h(5))];
        self.prograssSlider.minimumValue = 0;//设置最小值
        self.prograssSlider.maximumValue = 1;//设置最大值
        self.prograssSlider.value = 0.05;
        self.prograssSlider.value = 0;//设置默认值
        [self.prograssSlider setThumbImage:Image(@"icon_yuan") forState:UIControlStateNormal];
        [_downView addSubview:self.prograssSlider];
        
        self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.playButton setImage:Image(@"icon_zanting") forState:UIControlStateNormal];
        [self.playButton setImage:Image(@"icon_bofang") forState:UIControlStateSelected];
        self.playButton.frame = CGRectMake(0, getMaxY(self.prograssSlider), _downView.height, _downView.height - self.prograssSlider.height);
        self.playButton.centerX = _downView.width / 2;
        [_downView addSubview:self.playButton];
        
        self.timeLabel = [UILabel labelWithTitle:@"00:00/00.00" frame:CGRectMake(getMaxX(self.playButton) + w(20), 0, w(250), self.playButton.height) font:font(28) textColor:WhiteColor bgColor:ClearColor];
        self.timeLabel.centerY = self.playButton.centerY;
        [_downView addSubview:self.timeLabel];
        
    }
    return _downView;
}

- (UIView *)upView{
    if (!_upView) {
        self.upView = [UIView viewWithFrame:self.upFrame bgColor:ClearColor];
        
        UIView *view = [UIView viewWithFrame:_upView.bounds bgColor:BlackColor];
        view.alpha = 0.5;
        [_upView addSubview:view];
        
        self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.backButton setImage:Image(@"btn_return") forState:UIControlStateNormal];
        self.backButton.frame = CGRectMake(0, 0, self.upView.height, self.upView.height);
        
        [_upView addSubview:self.backButton];
        
        
    }
    return _upView;
}




- (void)showOrHide{
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:0.3 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^{
        self.isShow = !self.isShow;
        switch (self.isShow) {
            case YES:
            {
                self.upView.y += self.upView.height;
                self.downView.y -= self.downView.height + h(25);
              
            }
                break;
            case NO:
            {
                self.upView.y -= self.upView.height;
                self.downView.y += self.downView.height + h(25);
            }
                break;
                
            default:
                break;
        }
        
    }completion:^(BOOL finished) {
        
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
